package com.commodity.Service.inventoryServiceImp;

import com.commodity.Dao.InventoryDao;
import com.commodity.Dao.inventoryDaoImp.InventoryDaoImp;
import com.commodity.Service.InventoryService;
import com.commodity.entity.Inventory;
import com.commodity.entity.InventoryData;
import com.commodity.entity.InventorySearchBean;
import com.commodity.utils.BeanFactory;
import com.commodity.utils.PaginateInfo;

import java.util.ArrayList;
import java.util.List;

public class InventoryServiceImp implements InventoryService {
    InventoryDao inventoryDao = BeanFactory.getInstance(InventoryDaoImp.class);

    @Override
    public List<Inventory> findAll(InventorySearchBean isb, PaginateInfo pi) {
        return inventoryDao.findAll(isb, pi);
    }

    @Override
    public boolean add(Inventory inventory1) {
        return inventoryDao.add(inventory1) > 0;
    }

    @Override
    public int delete(Integer[] intIds) {
        return inventoryDao.delete(intIds);
    }

    @Override
    public Inventory findById(Integer id) {
        return inventoryDao.findById(id);
    }

    @Override
    public boolean update(Inventory inventory1) {
        return inventoryDao.update(inventory1) > 0;
    }

    @Override
    public List<Inventory> findAllWareHouseId() {
        return inventoryDao.findAllWareHouseId();
    }

    @Override
    public List<Inventory> findByCommodityIds(String[] commodityIdsFromCommodityList, PaginateInfo pi) {
        return inventoryDao.findByCommodityIds(commodityIdsFromCommodityList,pi);
    }

    @Override
    public List<Inventory> findByWarehouseId(String warehouseId1,PaginateInfo pi) {
        return inventoryDao.findByWarehouseId(warehouseId1,pi);
    }

    @Override
    public List<InventoryData> findByCommodityId(String commodityId) {
        List<InventoryData> inventoryDataList = new ArrayList<>();
        List<Inventory> inventoryList = inventoryDao.findByCommodityId(commodityId);
        for (int i = 0; i < inventoryList.size(); i++) {
            InventoryData inventoryData = new InventoryData();
            inventoryData.setValue(inventoryList.get(i).getInventory());
            inventoryData.setName(inventoryList.get(i).getWarehouseId());
            inventoryDataList.add(inventoryData);
        }
        return inventoryDataList;
    }
}
